package cn.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.DirectSchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

public class Quartz {

	public static void main(String[] args) throws SchedulerException {
		// JobDetail
		JobDetail jobDetail = JobBuilder.newJob(FirstJob.class).withIdentity("firstJob", "firstJobGroup")
				.usingJobData("message", "firstJobMessage").build();
		// Trigger
		/*Trigger trigger = TriggerBuilder.newTrigger()
		  		.withIdentity("firstTrigger", "firstTriggerGroup")
				.usingJobData("triggerDouble", 123.321D).startNow()
				.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever()).build();*/
		/*SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("firstTrigger", "firstTriggerGroup")
				.usingJobData("triggerDouble", 123.321D)
				.startAt(new Date())
				.endAt(new Date())
				.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever()).build();*/
		CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("firstTrigger", "firstTriggerGroup")
				.usingJobData("triggerDouble", 123.321D)
				.startAt(new Date())
				.endAt(new Date())
				.withSchedule(CronScheduleBuilder.cronSchedule("")).build();
		// schedule
		SchedulerFactory factory = new StdSchedulerFactory();
		Scheduler scheduler = factory.getScheduler();
		/*DirectSchedulerFactory  factory = DirectSchedulerFactory.getInstance();
		Scheduler scheduler = factory.getScheduler();*/
		scheduler.start();
		System.out.println("Current Time Is: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		scheduler.scheduleJob(jobDetail, trigger);//近期trigger触发的时间
	}
}
